from django.shortcuts import render,HttpResponse
from app01 import models


def read(request):
    ret = models.UserInfo.objects.all().values_list()
    lst1 = []
    for i in ret:
        lst = list(i)
        lst.insert(4, i[3].strftime("%Y-%m-%d"))
        lst.pop(3)
        lst1.append(lst)
    return render(request, 'read.html', {'lst1': lst1})


def add(request):
    if request.method == 'GET':
        return render(request, 'add.html')
    else:
        name_new = request.POST.get('name')
        price_new = request.POST.get('price')
        data_new = request.POST.get('data')
        press_new = request.POST.get('press')
        models.UserInfo.objects.create(
            name=name_new,
            price=price_new,
            data=data_new,
            press=press_new
        )
        # return HttpResponse('添加成功！')
        return render(request, 'add_complete.html')


def add_complete(request):
    return render(request, 'add_complete.html')

# def dele(request):

